package com.camelot.boot.module.system.controller.admin.chatmessage1;

import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.camelot.boot.framework.common.pojo.PageParam;
import com.camelot.boot.framework.common.pojo.PageResult;
import com.camelot.boot.framework.common.pojo.CommonResult;
import com.camelot.boot.framework.common.util.object.BeanUtils;
import static com.camelot.boot.framework.common.pojo.CommonResult.success;

import com.camelot.boot.framework.excel.core.util.ExcelUtils;

import com.camelot.boot.framework.apilog.core.annotation.ApiAccessLog;
import static com.camelot.boot.framework.apilog.core.enums.OperateTypeEnum.*;

import com.camelot.boot.module.system.controller.admin.chatmessage1.vo.*;
import com.camelot.boot.module.system.dal.dataobject.chatmessage1.ChatMessage1DO;
import com.camelot.boot.module.system.service.chatmessage1.ChatMessage1Service;

@Tag(name = "管理后台 - AI 聊天消息")
@RestController
@RequestMapping("/system/chat-message1")
@Validated
public class ChatMessage1Controller {

    @Resource
    private ChatMessage1Service chatMessage1Service;

    @PostMapping("/create")
    @Operation(summary = "创建AI 聊天消息")
    @PreAuthorize("@ss.hasPermission('system:chat-message1:create')")
    public CommonResult<Long> createChatMessage1(@Valid @RequestBody ChatMessage1SaveReqVO createReqVO) {
        return success(chatMessage1Service.createChatMessage1(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新AI 聊天消息")
    @PreAuthorize("@ss.hasPermission('system:chat-message1:update')")
    public CommonResult<Boolean> updateChatMessage1(@Valid @RequestBody ChatMessage1SaveReqVO updateReqVO) {
        chatMessage1Service.updateChatMessage1(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除AI 聊天消息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('system:chat-message1:delete')")
    public CommonResult<Boolean> deleteChatMessage1(@RequestParam("id") Long id) {
        chatMessage1Service.deleteChatMessage1(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得AI 聊天消息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:chat-message1:query')")
    public CommonResult<ChatMessage1RespVO> getChatMessage1(@RequestParam("id") Long id) {
        ChatMessage1DO chatMessage1 = chatMessage1Service.getChatMessage1(id);
        return success(BeanUtils.toBean(chatMessage1, ChatMessage1RespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得AI 聊天消息分页")
    @PreAuthorize("@ss.hasPermission('system:chat-message1:query')")
    public CommonResult<PageResult<ChatMessage1RespVO>> getChatMessage1Page(@Valid ChatMessage1PageReqVO pageReqVO) {
        PageResult<ChatMessage1DO> pageResult = chatMessage1Service.getChatMessage1Page(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ChatMessage1RespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出AI 聊天消息 Excel")
    @PreAuthorize("@ss.hasPermission('system:chat-message1:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportChatMessage1Excel(@Valid ChatMessage1PageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ChatMessage1DO> list = chatMessage1Service.getChatMessage1Page(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "AI 聊天消息.xls", "数据", ChatMessage1RespVO.class,
                        BeanUtils.toBean(list, ChatMessage1RespVO.class));
    }

}